package leecode

import "sort"

func sortList148(head *ListNode) *ListNode {
	if head == nil {
		return nil
	}
	arr := make([]int, 0)
	for head != nil {
		arr = append(arr, head.Val)
		head = head.Next
	}
	sort.Ints(arr)
	list := &ListNode{Val: arr[0]}
	tail := list
	for i := 1; i < len(arr); i++ {
		tail.Next = &ListNode{Val: arr[i]}
		tail = tail.Next
	}
	return list
}
